package com.ll.beautymall.ui.home.indexfragment.presenter;

import com.ll.beautymall.bean.Banner;
import com.ll.beautymall.bean.CategoryList;
import com.ll.beautymall.bean.ModelContent;
import com.ll.beautymall.ui.home.indexfragment.model.HeaderBiz;
import com.ll.beautymall.ui.home.indexfragment.model.OnGetCategoryListLisenter;
import com.ll.beautymall.ui.home.indexfragment.model.OnGetHeaderLisenter;
import com.ll.beautymall.ui.home.indexfragment.model.OnGetModelLisenter;
import com.ll.beautymall.ui.home.indexfragment.view.IContentView;
import com.ll.beautymall.ui.nine.view.INineView;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/10/21.
 * Banner和Model应作为一个完整的数据源传回，作为ListView的数据源
 */
public class HeaderPresenter {
    private IContentView contentView;
    private INineView nineView;
    private HeaderBiz headerBiz;
    private List<Banner> mBanners;
    private List<ModelContent> mContents;

    public HeaderPresenter(IContentView view) {
        contentView = view;
        headerBiz = new HeaderBiz();
    }

    public HeaderPresenter(INineView view) {
        nineView = view;
        headerBiz = new HeaderBiz();
    }

    public void setBannerData(HashMap<String, String> parameters) {
        headerBiz.getBannerData(parameters, new OnGetHeaderLisenter() {
            @Override
            public void onSucced(List<Banner> banners) {
                mBanners = banners;
                contentView.setBannerData(banners);
            }

            @Override
            public void onFailed(String errorMsg) {
                contentView.showErrorMsg(errorMsg);
            }
        });
    }

    public void setModelData(HashMap<String, String> parameters) {
        headerBiz.getModelData(parameters, new OnGetModelLisenter() {
            @Override
            public void onSucced(List<ModelContent> modelContents) {
                if (modelContents != null) {
                    mContents = modelContents;
                    contentView.setModelData(modelContents);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                contentView.showErrorMsg(errorMsg);
            }
        });
    }

    public void setNineCategoryData(HashMap<String, String> parameters) {
        headerBiz.getCategoryList(parameters, new OnGetCategoryListLisenter() {
            @Override
            public void onSucced(CategoryList categoryList) {
                if (categoryList != null) {
                    nineView.setCategoryListData(categoryList);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                nineView.showErrorMsg(errorMsg);
            }
        });
    }

    public void setCategoryData(HashMap<String, String> parameters) {
        headerBiz.getCategoryList(parameters, new OnGetCategoryListLisenter() {
            @Override
            public void onSucced(CategoryList categoryList) {
                if (categoryList != null) {
                    contentView.setCategoryListData(categoryList);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                contentView.showErrorMsg(errorMsg);
            }
        });
    }
}
